package main

import (
	"fmt"
	"log"
	"os"
	"strconv"
)

type Env struct {
	S Storage
}

func getEnv() *Env {
	addr := os.Getenv("APP_REDIS_ADDR")
	if addr == "" {
		addr = "localhost:6379"
	}
	password := os.Getenv("APP_REDIS_PASSWD")
	if password == "" {
		password = "l7y8c9"
	}
	dbS := os.Getenv("APP_REDIS_DB")
	if dbS == "" {
		dbS = "0"
	}
	db, err := strconv.Atoi(dbS)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Sprintf("connect to redis (addr: %s password: %s, db: %d)", addr, password, db)
	r := NewRedisCli(addr, password, db)
	return &Env{
		S: r,
	}
}
